package org.andrewwinter.tescopricewar;

public class Volume
{
    private int numberInPack;
    private int weightOrMeasure;
    private Unit unit;

    public Volume(final int weightOrMeasure, final Unit unit, final int numberInPack)
    {
        this.weightOrMeasure = weightOrMeasure;
        this.unit = unit;
        this.numberInPack = numberInPack;
    }

    @Override
    public boolean equals(Object obj)
    {
        if (!(obj instanceof Volume))
            return false;

        final Volume cast = (Volume) obj;

        if (numberInPack != cast.numberInPack)
            return false;

        if (unit == cast.unit && weightOrMeasure != cast.weightOrMeasure)
            return false;

        if (unit == Unit.ML && cast.unit == Unit.CL && cast.weightOrMeasure * 10 != weightOrMeasure)
            return false;

        if (cast.unit == Unit.ML && unit == Unit.CL && weightOrMeasure * 10 != cast.weightOrMeasure)
            return false;

        if (unit == Unit.ML && cast.unit == Unit.L && cast.weightOrMeasure * 1000 != weightOrMeasure)
            return false;

        if (cast.unit == Unit.ML && unit == Unit.L && weightOrMeasure * 1000 != cast.weightOrMeasure)
            return false;

        return true;
    }

    @Override
    public String toString()
    {
        if (numberInPack > 1)
        {
            return "" + numberInPack + " x " + weightOrMeasure + unit.getSymbol();
        }
        else
        {
            return "" + weightOrMeasure + unit.getSymbol();
        }
    }
}
